#include "If.h"
#include <algorithm>
#include <iostream>
#include <map>
#include <memory>

template <typename T>
auto get_value(T t)
{
    if constexpr (std::is_pointer_v<T>)
        return *t;
    else
        return t;
}

void ifWithConstexpr()
{
    auto pi = std::make_unique<int>(9);
    int i = 9;
    std::cout << "the value is: " << get_value(pi.get()) << "\n";
    std::cout << "the value is: " << get_value(i) << "\n";
}

std::map<int, std::string> m;

void ifWithInitializer()
{
    if (auto it = m.find(10); it != m.end()) {
        std::cout << "number found" << std::endl;
    } else {
        std::cout << "number not found" << std::endl;
    }
    std::string s = "while";
    if (auto keywords = { "if", "for", "while" };
        std::any_of(keywords.begin(), keywords.end(),
            [&s](const char* kw) { return s == kw; })) {
        std::cout << "keyword found" << std::endl;
    } else {
        std::cout << "keyword not found" << std::endl;
    }
}

void switchWithInitializer()
{
    int a = 1;
    switch (a = 2; a) {
    case 1:
        std::cout << "one";
        break;
    case 2:
        std::cout << "two";
        break;
    case 3:
        std::cout << "three";
        break;
    default:
        std::cout << "default";
        break;
    }
    std::cout << std::endl;
}
